package ru.ipccenter.beans;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import ru.ipccenter.entities.Human;

/**
 * Message-Driven Bean implementation class for: HumanMDBean
 */
@MessageDriven(
		activationConfig = { @ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Topic")
		})
public class HumanMDBean extends HumanBean implements MessageListener {
	@EJB
    HumanBeanLocal hb;
    
    public HumanMDBean() {
    }
	
	/**
     * @see MessageListener#onMessage(Message)
     */
    public void onMessage(Message message) {
    	if (message instanceof ObjectMessage){
    		try {
				Object obj = ((ObjectMessage)message).getObject();
				if (obj instanceof Human){
					hb.create((Human) obj);
				}
    		} catch (JMSException e) {
				e.printStackTrace();
			}
    	}
    }

}
